Skip to content

Depreciation Warning <Component>.defaultProps #955

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
sarojshakya01 opened this issue May 5, 2025 · 3 comments
Open

Depreciation Warning <Component>.defaultProps #955

sarojshakya01 opened this issue May 5, 2025 · 3 comments

Comments

@sarojshakya01
Copy link

I am encountering following irritating warning in my console. Has it been addressed in the beta version? Will be it be updated in the future release?
"Support for defaultProps will be removed from function components in a future major release. Use JavaScript default parameters instead."

@masahmad71
Copy link

for those who are looking for replacement, take a look at @uiw/react-color.

@Taimoor79
Copy link

@sarojshakya01 open console and check file name like in my case

Image

Then click on the file name and you get to know where the actual issue is, like in my case check the cursor position

Image

Then hover over the file name and you will get file path and then open file in any editor and remove default props and assign their value directly

Library code before:
`var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };

import React, { isValidElement } from 'react';
import reactCSS from 'reactcss';
import * as checkboard from '../../helpers/checkboard';

export var Checkboard = function Checkboard(_ref) {
var white = _ref.white,
grey = _ref.grey,
size = _ref.size,
renderers = _ref.renderers,
borderRadius = _ref.borderRadius,
boxShadow = _ref.boxShadow,
children = _ref.children;

var styles = reactCSS({
'default': {
grid: {
borderRadius: borderRadius,
boxShadow: boxShadow,
absolute: '0px 0px 0px 0px',
background: 'url(' + checkboard.get(white, grey, size, renderers.canvas) + ') center left'
}
}
});
return isValidElement(children) ? React.cloneElement(children, _extends({}, children.props, { style: _extends({}, children.props.style, styles.grid) })) : React.createElement('div', { style: styles.grid });
};

Checkboard.defaultProps = {
size: 8,
white: 'transparent',
grey: 'rgba(0,0,0,.08)',
renderers: {}
};

export default Checkboard;`

Library Code After:
`var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };

import React, { isValidElement } from 'react';
import reactCSS from 'reactcss';
import * as checkboard from '../../helpers/checkboard';

// Checkboard.defaultProps = {
// size: 8,
// white: 'transparent',
// grey: 'rgba(0,0,0,.08)',
// renderers: {}
// };

export var Checkboard = function Checkboard(_ref) {
var white = 'transparent',
grey = 'rgba(0,0,0,.08)',
size = 8,
renderers = {},
borderRadius = _ref.borderRadius,
boxShadow = _ref.boxShadow,
children = _ref.children;

var styles = reactCSS({
'default': {
grid: {
borderRadius: borderRadius,
boxShadow: boxShadow,
absolute: '0px 0px 0px 0px',
background: 'url(' + checkboard.get(white, grey, size, renderers.canvas) + ') center left'
}
}
});
return isValidElement(children) ? React.cloneElement(children, _extends({}, children.props, { style: _extends({}, children.props.style, styles.grid) })) : React.createElement('div', { style: styles.grid });
};

export default Checkboard;`

Then build your project again using yarn build or npm run build

@Taimoor79
Copy link

@masahmad71 I installed this library @uiw/react-color and then got to know that its have a lot of errors like when change alpha/opacity of color then this library returns NaN and I am unable to change color.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants